import Vue from 'vue'
import VueLocalStorage from 'vue-ls';

Vue.use(VueLocalStorage);

const state = {
  authorization: Vue.ls.get('authorization'),
}
const mutations = {
  LOGIN_IN: (state, token) => {
    Vue.ls.set('authorization', token.authorization);
    state.authorization = token.authorization;
  },
  LOGIN_OUT: (state) => {
    Vue.ls.remove('authorization');
    state.authorization = '';
  }

}
const actions = {
  loginin({ commit }, token) {
    return new Promise(resolve => {
      commit('LOGIN_IN', token)
      resolve()
    })
  },
  loginOut({ commit }) {
    return new Promise(resolve => {
      commit('LOGIN_OUT')
      resolve()
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
